from app.db import db, BaseEmbeddedDocument

from app.libs.enums import CHANGE_CHECK_TYPE_TUPLE


class AlertSettings(BaseEmbeddedDocument):
    enable = db.DictField(default={
        "asset": True,
        "vul": True,
        "ssl": True,
        "cyd": True,
        "securityEvent": True,
        "http": True,
        "ping": True,
        "hostVul": True,
        "content": True,
        "changeCheck": True
    })
    notification = db.DictField(default={
        "email": True,
        "sms": True,
        "wechat": True,
        "inBox": True
    })
    smsAllowedTime = db.DictField(default={
        "start": "00:00:00",
        "end": "23:59:59"
    })
    emailAllowedTime = db.DictField(default={
        "start": "00:00:00",
        "end": "23:59:59"
    })

    smsDailyLimit = db.LongField(min_value=0, default=10)
    emailDailyLimit = db.LongField(min_value=0, default=10)


class AlertEnableDetail(BaseEmbeddedDocument):
    vul = db.ListField(db.StringField(), default=["critical", "high", "medium", "low"])
    content = db.ListField(db.StringField(), default=["keyword", "privacy_disclosure"])
    hostVul = db.ListField(db.StringField(), default=["critical", "high", "medium", "low"])
    securityEvent = db.ListField(db.StringField(), default=[
        "black_links", "broken_links", "cryjack", "malscan", "foreign_links"])
    ssl = db.ListField(db.StringField(), default=["protocol", "certificate"])
    changeCheck = db.ListField(db.StringField(), default=["high", "low"])


class AlertGroup(db.Document):
    """{
    "isDefault": true,
    "uid": {
        "$oid": "604d7940405c990011467f39"
    },
    "__v": 0,
    "enable": true,
    "includeWechat": true,
    "name": "默认组",
    "receiverIds": [{
        "$oid": "604d7940405c990011467f3b"
    }]
}

    Args:
        db ([type]): [description]
    """
    isDefault = db.BooleanField(default=False)
    enable = db.BooleanField(default=True)
    uid = db.ObjectIdField()
    includeWechat = db.BooleanField()
    name = db.StringField(default="默认告警策略")
    receiverIds = db.ListField(db.ObjectIdField())
    alertSettings = db.EmbeddedDocumentField(AlertSettings, default=AlertSettings)
    alertEnableDetail = db.EmbeddedDocumentField(AlertEnableDetail, default=AlertEnableDetail)

    meta = {
        "collection": "alertgroups",
        "strict": False
    }
